home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / configisc.py < prev    next >
Encoding:
Python Source  |  2009-03-30  |  1.4 KB  |  45 lines

  1. #!/usr/bin/python
  2. # Example demonstrating how to use the configuration/commandline system
  3. # for object setup.
  4.  
  5. # This parses the given config file in 'ISC' style where the sections
  6. # represent object instances and shows how to iterate over the sections.
  7. # Pass it the sample apt-ftparchive configuration,
  8. # doc/examples/ftp-archive.conf
  9. # or a bind8 config file..
  10.  
  11. import apt_pkg
  12. import sys
  13. import posixpath
  14.  
  15. ConfigFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv)
  16.  
  17. if len(ConfigFile) != 1:
  18.     print "Must have exactly 1 file name"
  19.     sys.exit(0)
  20.  
  21. Cnf = apt_pkg.newConfiguration()
  22. apt_pkg.ReadConfigFileISC(Cnf, ConfigFile[0])
  23.  
  24. # Print the configuration space
  25. #print "The Configuration space looks like:"
  26. #for I in Cnf.keys():
  27. #   print "%s \"%s\";" % (I, Cnf[I])
  28.  
  29. # bind8 config file..
  30. if Cnf.Exists("Zone"):
  31.     print "Zones: ", Cnf.SubTree("zone").List()
  32.     for I in Cnf.List("zone"):
  33.         SubCnf = Cnf.SubTree(I)
  34.         if SubCnf.Find("type") == "slave":
  35.             print "Masters for %s: %s" % (
  36.                 SubCnf.MyTag(), SubCnf.ValueList("masters"))
  37. else:
  38.     print "Tree definitions:"
  39.     for I in Cnf.List("tree"):
  40.         SubCnf = Cnf.SubTree(I)
  41.         # This could use Find which would eliminate the possibility of
  42.         # exceptions.
  43.         print "Subtree %s with sections '%s' and architectures '%s'" % (
  44.             SubCnf.MyTag(), SubCnf["Sections"], SubCnf["Architectures"])
  45.